import axios from '@/plugins/axios'
import Qs from 'qs'

// 发送邮箱验证码
export function sendCaptcha(email) {
  return axios({
    url: 'captcha',
    method: 'post',
    data: { email: email },
    transformRequest: [function (data) {
      let ret = '';
      ret = Qs.stringify(data);
      return ret;
    }],
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 注册
export function register(form) {
  return axios({
    url: 'register',
    method: 'POST',
    data: {
      ...form
    }
  })
}

// 检查此用户名是否存在
export function registerExistUsername(username) {
  return axios({
    url: 'register/exist/username',
    method: 'GET',
    params: { username },
  })
}


// 检查昵称是否存在
export function registerExistNickname(nickName) {
  return axios({
    url: 'register/exist/nickname',
    method: 'GET',
    params: { nickName },
  })
}